package com.seari.custody.component;

import com.google.api.client.repackaged.com.google.common.base.Strings;
import com.seari.custody.bean.Meeting;
import com.seari.custody.bean.OpenMeeting;
import com.seari.custody.bean.User;
import com.seari.custody.service.UserService;
import com.seari.custody.util.EncryptUtils;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class MeetingInviteLink {
    @Autowired
    private UserService userService;
    @Value("${innerLink}")
    private String innerLink;
    @Value("${outerLink}")
    private String outerLink;
    @Value("${userPassword}")
    private String userPassword;
    @Autowired
    private WebserviceClient webserviceClient;

    @SneakyThrows
    public OpenMeeting genInviteLink(Meeting meeting, String userNumber) {
        OpenMeeting openMeeting = new OpenMeeting();

        String roomId = meeting.getSite();
        String roomPwd = "1234";
        String loginAddress = webserviceClient.getLoginAddress();
        openMeeting.setRoomId(roomId);
        openMeeting.setRoomPwd(roomPwd);
        openMeeting.setLink(loginAddress);
        if (Strings.isNullOrEmpty(userNumber)) {
            //游客登录
            openMeeting.setUserName("游客登录");
            openMeeting.setFileAddress(outerLink + "/download/CloudLauncherV1.0.0.7.exe");
            openMeeting.setMeetingAddress(outerLink + "/download/FastMeeting_Cloud_for_Windows_V3.32.2.27.exe");

        } else {
            //会议链接 userNumber从token获取
            User user = userService.qryUserByNumber(userNumber);
            String userName = user.getUsername();
            String userPwd = EncryptUtils.encode(userPassword);
            openMeeting.setUserName(userName);
            openMeeting.setUserPwd(userPwd);
            openMeeting.setFileAddress(innerLink + "/download/launch.exe");
            openMeeting.setMeetingAddress(innerLink + "/download/FastMeeting_Cloud_for_Windows_V3.32.2.27.exe");

        }
//        switch (inviteLinkType) {
//            case PC_ANONYMOUS:
//                return String.format(innerLink + "/launch/toEnterMeeting.do?roomID=%s&userName=%s&userType=0&link=%s&roomPwd=%s", roomId, "游客登录", webserviceClient.getLoginAddress(), roomPwd);
//            case PC_USR:

//                return String.format(innerLink + "/launch/toEnterMeeting.do?roomID=%s&userName=%s&userPwd=%s&link=%s&pwdEncrypted=1&roomPwd=%s", roomId, userName, userPwd, webserviceClient.getLoginAddress(), roomPwd);
//            case IOS:
//
//                //                return "launcher.FMEnt://" + escape("openByLink(1)userType(1)userName(hst)userPwd(111)auto(1)svrAddress(192.168.5.67)svrPort(1089)");
//
//            case ANDROID:
//
//                break;
//
//
//            //                return "launcher.fment://link=" + encodeURIComponent("xxxx") + "/uname=" + encodeURIComponent("xxxx") + "/rid=" + encodeURIComponent("xxxx") + "/rpwd=" + encodeURIComponent("xxxx") + "/utype=" + encodeURIComponent("xxxx")
//
//
//            default:
//                throw new BIZException("邀请链接类型有误");
//        }

        return openMeeting;
    }


    public static void main(String[] args) {


    }

}